package pl.agh.pp.zephyr.model;

import java.io.Serializable;

/**
 * Reprezentuje coś co ma interfejst sieciowy.
 * 
 * Przeładowanie hashcode gwarantuje unikalność hashy
 * */
public class Host implements Serializable {
	
	private static final long serialVersionUID = -8655187478069960342L;

	public static final String UNKNOWN_IP = "-1";

	public final String ip, port;
	
	private String alias;

	public Host(String ip, String port) {
		this.ip = ip;
		this.port = port;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((ip == null) ? 0 : ip.hashCode());
		result = prime * result + ((port == null) ? 0 : port.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Host other = (Host) obj;
		if (ip == null) {
			if (other.ip != null)
				return false;
		} else if (!ip.equals(other.ip))
			return false;
		if (port == null) {
			if (other.port != null)
				return false;
		} else if (!port.equals(other.port))
			return false;
		return true;
	}

	public String getAlias() {
		return alias;
	}

	public void setAlias(String alias) {
		this.alias = alias;
	}

	@Override
	public String toString() {
		return "Host [ip=" + ip + ", port=" + port + ", alias=" + alias + "]";
	}
	
}
